//
//  NumberChecker.m
//  TruckSelling
//
//  Created by enghou on 2017/12/6.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

#import "NumberChecker.h"

@implementation NumberChecker

+(BOOL)validAccount:(NSString *)account{
    if ([account length] > 0) {
        return YES;
    }
    return NO;
}

+ (BOOL)isIPAddress:(NSString *)ip {
    //简化版 因为输入框只能输入数字与.
    NSArray *componds = [ip componentsSeparatedByString:@"."];
    if ([componds count] != 4) {
        return NO;
    }
    BOOL v = YES;
    for (NSString *s in componds) {
        if (s.integerValue > 255) {
            v = NO;
            break;
        }
    }
    return v;
}

+(BOOL)validPass:(NSString *)pass{
    if ([pass length] > 0) {
        return YES;
    }
    return NO;
}

+(BOOL)validPhone:(NSString *)mobileNum{
    if (mobileNum.length != 11)
    {
        return NO;
    }
    
    NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";
    
    NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d{8}$)|(^1705\\d{7}$)";
    
    NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d{8}$)|(^1709\\d{7}$)";
    
    NSString *CT = @"(^1(33|53|77|8[019])\\d{8}$)|(^1700\\d{7}$)";
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES)){
        return YES;
    }else
    {
        return NO;
    }
}

+(BOOL)validCarCardNo:(NSString *)carID{
    if (carID.length!=7) {
        return NO;
    }
    NSString *carRegex = @"^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]{1}[A-Z]{1}[0-9A-Z]{5}$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
    return [carTest evaluateWithObject:carID];
}

@end
